package com.nd.bdc.presto.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

@Configuration
public class WebMvcConfig extends ResourceHttpRequestHandler implements WebMvcConfigurer {


    @Autowired
    private Environment env;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String contextPath = env.getProperty("server.servlet.context-path");
        String path = "/static/**";
        if(contextPath != null && !contextPath.isEmpty() ){
//            path = "/" + contextPath + "/static/**";
        }
        if(!registry.hasMappingForPattern(path)){
            registry.addResourceHandler(path).addResourceLocations("classpath:/static/");
        }
    }



}
